<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Student_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * current contests
     *
     * this will get a list of contests which are running and open for voting
     * this method only get the contest ids
     *
     * @return <type>
     */
public function get_student_by_id($student_id,$academic_session)
    {
		$this->db->select('*');
		$this->db->from('student');
		$this->db->where('student_id', $student_id);
		$this->db->where('academic_session', $academic_session);
		$query = $this->db->get();
		return $query->result_array(); 
    }
    public function get_student_edu_by_id($student_id,$academic_session)
    {
    	$this->db->select('*');
    	$this->db->from('education');
    	$this->db->where('student_id', $student_id);
    	$this->db->where('academic_session', $academic_session);
    	$query = $this->db->get();
    	return $query->result_array();
    }
  /**
    * Fetch student data from the database
    * possibility to mix search, filter and order
    * @param int $session_id 
    * @param string $search_string 
    * @param strong $order
    * @param string $order_type 
    * @param int $limit_start
    * @param int $limit_end
    * @return array
    */
    public function get_students($academic_session=null,$group_id=null, $search_string=null, $order=null, $order_type='Asc', $limit_start, $limit_end)
    {
	    
		$this->db->select("student_id,group_id,student_name,fathername,mothername,sectionname,DATE_FORMAT(dob,('%d-%m-%Y')) dob,religion,bloodgroup,academic_session,remarks");
		$this->db->from('student');
		if($academic_session != null && $academic_session != 0){
		    $this->db->where('academic_session', $academic_session);
		}
		if($group_id!=null && $group_id!='')
		{
			$this->db->where('group_id', $group_id);
		}
		if($search_string){
			//$like = "student_id like '%".$search_string."%' OR student_name like '%".$search_string."%' OR fathername like '%".$search_string."%' OR mothername like '%".$search_string."%'";
			//$this->db->where($like);
			$this->db->like('student_id', $search_string);
			$this->db->or_like('student_name', $search_string);
			$this->db->or_like('fathername', $search_string);
			$this->db->or_like('mothername', $search_string);
			
		}

		//$this->db->group_by('student_id');

		if($order){
			$this->db->order_by($order, $order_type);
		}else{
		    $this->db->order_by('student_id', $order_type);
		}


		$this->db->limit($limit_start, $limit_end);
		//$this->db->limit('4', '4');


		$query = $this->db->get();
		
		return $query->result_array();
	    //echo $query->num_rows();    
    }

    function get_students_with_option($academic_session,$group_id,$limit_start,$limit_end)
    {
    	$this->db->select("student_id,group_id,student_name,fathername,mothername,sectionname,DATE_FORMAT(dob,('%d-%m-%Y')) dob,religion,bloodgroup,academic_session");
    	$this->db->from('student');
    	$this->db->where('academic_session', $academic_session);
    	$this->db->where('group_id', $group_id);
        $this->db->order_by('student_id');
        $this->db->limit($limit_start, $limit_end);
    	$query = $this->db->get();
    	
    	return $query->result_array();
    }
    /**
    * Count the number of rows
    * @param int $manufacture_id
    * @param int $search_string
    * @param int $order
    * @return int
    */
    function count_students($academic_session=null,$group_id=null, $search_string=null, $order=null)
    {
		$this->db->select('*');
		$this->db->from('student');
		if($academic_session != null && $academic_session != 0){
			$this->db->where('academic_session', $academic_session);
		}
		if($group_id != null && $group_id != ''){
			$this->db->where('group_id', $group_id);
		}
		if($search_string){
			$this->db->like('student_name', $search_string);
		}
		if($order){
			$this->db->order_by($order, 'Asc');
		}else{
		    $this->db->order_by('student_id', 'Asc');
		}
		$query = $this->db->get();
		return $query->num_rows();        
    }

/////////////////////////////////////////////////////////////////////
    function check_no_of_subject($academic_session,$group_id,$needAssign)
    {
    	$sql="select smd.student_id,count(*) noofsubjet
			from subj_marks_detail smd,student st
			where smd.student_id=st.student_id
			and smd.academic_session=st.academic_session
    		and smd.academic_session='".$academic_session."'
			and st.group_id='".$group_id."'
			group by smd.student_id
			having count(*)!=".$needAssign;
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }
    ////////////////////////////////////////////////////////////
    function get_group_std_subjects($academic_session,$group_id,$student_id)
    {
    	$sql="select sub.subject_id group_subject_id,sub.subject_name,stm.subject_id, stm.is_opt from subjects sub LEFT JOIN
		(select subject_id, is_opt from  subj_marks_detail where student_id='".$student_id."') stm
		 ON sub.subject_id=stm.subject_id
		where sub.group_id='".$group_id."'";
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }
    
    ////////////////////////////////////////////////////////////
    function assing_individual_std_subjects($student_id,$academic_session,$subjects,$chk_subjects,$opt_subjects)
    {
    	$flag=0;
    	$i=0;
    	foreach( $subjects as $key => $sub_id )
    	{
    		if($chk_subjects[$i]==1)
    		{
    			/*
    			$sql="IF EXISTS (SELECT * FROM subj_marks_detail 
    			                       WHERE student_id='$student_id' and subject_id='$subjects[$i]')
    			UPDATE subj_marks_detail SET is_opt='$opt_subjects[$i]' WHERE student_id='$student_id' and subject_id='$subjects[$i]'
    			ELSE
    			INSERT INTO subj_marks_detail(student_id, academic_session, subject_id, is_opt) 
    			          VALUES ('$student_id', '$academic_session', '$subjects[$i]','$opt_subjects[$i]')";
    			
    			*/
    			$sql="INSERT INTO subj_marks_detail(student_id, academic_session, subject_id) 
    			          VALUES ('$student_id', '$academic_session', '$subjects[$i]')
    			       ON DUPLICATE KEY
    			       UPDATE  is_opt='$opt_subjects[$i]'";
    			$query=$this->db->query($sql);
    		}
    		else
    		{
    			$sql="delete from subj_marks_detail  WHERE student_id='$student_id' and subject_id='$subjects[$i]'";
    			$query=$this->db->query($sql);
    		}
    		$i++;
    		$flag=1;
    	}
    	
    	
    	return $flag;
    }
    //////////////////////////////////////////
    
    function get_group_subjects($academic_session,$group_id)
    {
    	$sql="select subject_id,subject_name from subjects where group_id='".$group_id."'";
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }
    

public function get_std_MarksDetail($academic_session,$group_id)
    {
	    
    	$sql="select sm.student_id,s.student_name,s.group_id,s.academic_session,s.section,sm.subject_id,sub.subject_name,sm.is_opt,sm.f_y_1st_att,
    		sm.f_y_1st_ct,sm.f_y_1st_ht_mcq,sm.f_y_1st_ht_cq,
    		f_y_1st_ht_total,f_y_1st_gran_total,is_pass_f_y_1_t,f_y_pro_att,f_y_pro_ht_mcq,
			f_y_pro_ht_cq,f_y_pro_ht_prac,f_y_pro_ht_total,f_y_pro_gpa,is_pass_f_y_pro,
			s_y_pre_att,s_y_pre_ct,s_y_pre_ht_mcq,s_y_pre_ht_cq,s_y_pre_ht_total,s_y_pre_gran_total,
			is_pass_s_y_pre,s_y_t_p1_mcq,s_y_t_p1_cq,s_y_t_p1_total,s_y_t_p2_mcq,s_y_t_p2_cq,
			s_y_t_p2_total,s_y_test_gra_total,s_y_test_gpa,is_pass_s_y_test,s_y_test_att,s_y_prac_att
			from subj_marks_detail sm, student s,subjects sub
			where sm.student_id=s.student_id
			and sm.academic_session=s.academic_session
    		and  s.group_id=sub.group_id
			and sm.subject_id=sub.subject_id
    		and sm.academic_session='".$academic_session."'	 
    		and s.group_id='".$group_id."'
			order by sm.student_id,sub.subject_order";
		$query=$this->db->query($sql);
		return $query->result_array(); 	
    }
    ///////////////////////////////////////////////////////////////////
    public function get_std_MarksDetail_limit($academic_session,$group_id,$limitStart,$limitNo)
    {
    	 
    	$sql="select sm.student_id,s.student_name,s.group_id,s.academic_session,s.section,sm.subject_id,if(sm.is_opt=1,concat(sub.subj_sort_name,' (O)'),sub.subj_sort_name) subject_name,sm.is_opt,sm.f_y_1st_att,
    		sm.f_y_1st_ct,sm.f_y_1st_ht_mcq,sm.f_y_1st_ht_cq,
    		f_y_1st_ht_total,f_y_1st_gran_total,is_pass_f_y_1_t,f_y_pro_att,f_y_pro_ht_mcq,
			f_y_pro_ht_cq,f_y_pro_ht_prac,f_y_pro_ht_total,f_y_pro_gpa,is_pass_f_y_pro,
			s_y_pre_att,s_y_pre_ct,s_y_pre_ht_mcq,s_y_pre_ht_cq,s_y_pre_ht_total,s_y_pre_gran_total,
			is_pass_s_y_pre,s_y_t_p1_mcq,s_y_t_p1_cq,s_y_t_p1_total,s_y_t_p2_mcq,s_y_t_p2_cq,
			s_y_t_p2_total,s_y_test_gra_total,s_y_test_gpa,is_pass_s_y_test,s_y_test_att,s_y_prac_att
			from subj_marks_detail sm, (select * from student where group_id='".$group_id."' and academic_session='".$academic_session."' order by student_id asc limit ".$limitStart." , ".$limitNo.") s,subjects sub
			where sm.student_id=s.student_id
			and sm.academic_session=s.academic_session
    		and  s.group_id=sub.group_id
			and sm.subject_id=sub.subject_id
    		and sm.academic_session='".$academic_session."'
    		and s.group_id='".$group_id."'
			order by sm.student_id,sub.subject_order";
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }
    ///////////////////////////////////////////////////////////////////
    public function get_std_MarksDetail_by_studentID($student_id,$academic_session)
    {
    	 
    	$sql="select sm.student_id,s.student_name,s.group_id,s.academic_session,s.section,sm.subject_id,if(sm.is_opt=1,concat(sub.subj_sort_name,' (O)'),sub.subj_sort_name)subject_name,sm.is_opt,sm.f_y_1st_att,
    		sm.f_y_1st_ct,sm.f_y_1st_ht_mcq,sm.f_y_1st_ht_cq,
    		f_y_1st_ht_total,f_y_1st_gran_total,is_pass_f_y_1_t,f_y_pro_att,f_y_pro_ht_mcq,
			f_y_pro_ht_cq,f_y_pro_ht_prac,f_y_pro_ht_total,f_y_pro_gpa,is_pass_f_y_pro,
			s_y_pre_att,s_y_pre_ct,s_y_pre_ht_mcq,s_y_pre_ht_cq,s_y_pre_ht_total,s_y_pre_gran_total,
			is_pass_s_y_pre,s_y_t_p1_mcq,s_y_t_p1_cq,s_y_t_p1_total,s_y_t_p2_mcq,s_y_t_p2_cq,
			s_y_t_p2_total,s_y_test_gra_total,s_y_test_gpa,is_pass_s_y_test,s_y_test_att,s_y_prac_att
			from subj_marks_detail sm, student s,subjects sub
			where sm.student_id=s.student_id
			and sm.academic_session=s.academic_session
			and sm.subject_id=sub.subject_id
    	    and sub.group_id=s.group_id
    		and sm.academic_session='".$academic_session."'
        		and sm.student_id='$student_id'
        		order by sm.student_id,sub.subject_order";
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }
    ////////////////////////////////////////////////////////
   function get_exam_total_marks()
    {
    	$this->db->select('*');
    	$this->db->from('sub_exam_total_marks');
    	$query = $this->db->get();
    	//$ExamTotalMarks=$query->result_array();
    	//return $ExamTotalMarks;
    	$ExamTotalMarks=array();
    	foreach( $query->result_array() as $row )
    	{
    		$sub=$row['subject_id'];
    		$ExamTotalMarks[$sub]=$row;
    	}
    	return $ExamTotalMarks;
    }    
    
    ///////////////////////////////////////////////
    function get_exam_total_marksByGroupID($group_id)
    {
    	$this->db->select('*');
    	$this->db->from('sub_exam_total_marks');
    	$this->db->where('group_id', $group_id);
    	$query = $this->db->get();
    	
    	return $query->result_array(); 	
    }
    
    function update_total_exam_marks($group_id, $subject_id, $data)
    {
    	$WhereArray = array('subject_id' => $subject_id, 'group_id' => $group_id);
    	$this->db->where($WhereArray);
    	$this->db->update('sub_exam_total_marks', $data);
    	$report = array();
    	$report['error'] = $this->db->_error_number();
    	$report['message'] = $this->db->_error_message();
    	if($report !== 0){
    		return true;
    	}else{
    		return false;
    	}
    }
    
    function get_student_attend_in_exam($academic_session,$group_id)
    {
    	$sql_main="select distinct smd.student_id from subj_marks_detail smd,student st 
			where smd.academic_session='".$academic_session."' and smd.student_id=st.student_id	  and st.group_id='".$group_id."'";
    		 
		$sql_cond_first_term=" and (f_y_1st_att!=0 OR f_y_1st_ht_mcq !=0 OR f_y_1st_ht_cq !=0 OR f_y_1st_ht_total!=0)";
		$sql_cond_promotion_test=" and (f_y_pro_att is not null OR f_y_pro_ht_mcq is not null OR f_y_pro_ht_cq is not null OR f_y_pro_ht_total is not null)";
		$sql_cond_pre_test=" and (s_y_pre_att is not null   OR s_y_pre_ht_mcq is not null OR s_y_pre_ht_cq is not null OR s_y_pre_ht_total is not null)";
		$sql_cond_test_examination=" and (s_y_t_p1_total is not null OR s_y_t_p2_total is not null OR s_y_test_gra_total is not null )";
		$query=$this->db->query($sql_main.$sql_cond_first_term);
		$StdAttendInExam=array();
		$StdAttendInExam['first_term']=$query->num_rows()==0?null:$query->num_rows();
		$query_pro=$this->db->query($sql_main.$sql_cond_promotion_test);
		$StdAttendInExam['promotion_test']=$query_pro->num_rows()==0?null:$query_pro->num_rows();
		$query_pre=$this->db->query($sql_main.$sql_cond_pre_test);
		$StdAttendInExam['pre_test']=$query_pre->num_rows()==0?null:$query_pre->num_rows();
		$query_test=$this->db->query($sql_main.$sql_cond_test_examination);
		$StdAttendInExam['test_examination']=$query_test->num_rows()==0?null:$query_test->num_rows();
		
    	return $StdAttendInExam;
    }
    
    function get_total_attendence($academic_session,$group_id)
    {
    	
    	$this->db->select('*');
    	$this->db->from('subj_attendance');
    	$this->db->where('academic_session', $academic_session);
    	$this->db->where('group_id', $group_id);
    	$query = $this->db->get();
    	$TotalAttendence=array();

    	foreach( $query->result_array() as $row )
    	{
    		$sub=$row['subject_id'].$row['section'];
    		$TotalAttendence[$sub]=$row;
    	}
    	return $TotalAttendence;
    }

    function get_exam_remarks($academic_session,$group_id)
    {
        $section=substr($academic_session,0,4);
		$is_even=$section%2;
		$stdLike="";
		if($group_id=="Science")
		{
			if($is_even==0)
				$stdLike="6%";
			else
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			if($is_even==0)
				$stdLike="2%";
			else
				$stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
		
		
    	$sql_first="select student_id,'Keep up your good study habits.' first_term_remarks from  std_exam_merit
	    where  first_term_merit between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Keep on trying.' first_term_remarks from  std_exam_merit
	    where  first_term_is_pass=1 and first_term_merit not between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Work hard.' first_term_remarks from  std_exam_merit
	    where  first_term_is_pass=0
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'";
    	
    	$sql_pro="select student_id,'Keep up your good study habits.' pro_test_remarks from  std_exam_merit
	    where  pro_test_merit between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Keep on trying.' pro_test_remarks from  std_exam_merit
	    where  pro_test_is_pass=1 and pro_test_merit not between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Work hard.' pro_test_remarks from  std_exam_merit
	    where  pro_test_is_pass=0
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'";
    	
    	$sql_pre_test="select student_id,'Keep up your good study habits.' pre_test_remarks from  std_exam_merit
	    where  pre_test_merit between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Keep on trying.' pre_test_remarks from  std_exam_merit
	    where  pre_test_is_pass=1 and pre_test_merit not between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Work hard.' pre_test_remarks from  std_exam_merit
	    where  pre_test_is_pass=0
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'";
    	
    	
    	
    	$sql_test="select student_id,'Keep up your good study habits.' test_remarks from  std_exam_merit
	    where  test_exam_merit between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Keep on trying.' test_remarks from  std_exam_merit
	    where  test_exam_is_pass=1 and test_exam_merit not between 1 and 20
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'
	    union
	    select student_id,'Work hard.' test_remarks from  std_exam_merit
	    where  test_exam_is_pass=0
	    and academic_session='".$academic_session."'
	    and student_id like '".$stdLike."'";
    	
	    
	$query_first=$this->db->query($sql_first);
	$query_pro=$this->db->query($sql_pro);
	$query_pre=$this->db->query($sql_pre_test);
	$query_test=$this->db->query($sql_test);
	
    $Exam_Remarks=array();

    	foreach( $query_first->result_array() as $row )
    	{
    		$student_id=$row['student_id'].'first_term_remarks';
    		$Exam_Remarks[$student_id]=$row['first_term_remarks'];
    	}
    	foreach( $query_pro->result_array() as $row )
    	{
    		$student_id=$row['student_id'].'pro_test_remarks';
    		$Exam_Remarks[$student_id]=$row['pro_test_remarks'];
    	}
    	foreach( $query_pre->result_array() as $row )
    	{
    		$student_id=$row['student_id'].'pre_test_remarks';
    		$Exam_Remarks[$student_id]=$row['pre_test_remarks'];
    	}
    	
    	foreach( $query_test->result_array() as $row )
    	{
    		$student_id=$row['student_id'].'test_remarks';
    		$Exam_Remarks[$student_id]=$row['test_remarks'];
    	}
    	
    	return $Exam_Remarks;
    }
    
    
public function get_std_general_info()
    {
	    
    	$sql="select st.student_id,group_id,student_name,st.academic_session, 
			religion,mother_lang,DATE_FORMAT(dob,'%d-%m-%Y') dob,fathername,mothername,permanentadd,presentaddress,village,
			postoffice,thana,district,ssc_board,ssc_year,ssc_group,ssc_reg_no,
			ssc_reg_year,ssc_centre,ssc_roll,ssc_gpa,ssc_opt,ssc_school,
			hsc_board,hsc_year,hsc_group,hsc_reg_no,hsc_reg_year,hsc_centre,
			hsc_roll,hsc_gpa,hsc_opt
			from student st,education edu
			where st.student_id=edu.student_id
			order by st.student_id";
		$query=$this->db->query($sql);
		return $query->result_array(); 	
    }    
    public function get_std_general_info_by_studentID($student_id,$academic_session)
    {
    	 
    	$sql="select st.student_id,group_id,student_name,st.academic_session,
			religion,mother_lang,DATE_FORMAT(dob,'%d-%m-%Y') dob,fathername,mothername,permanentadd,presentaddress,village,
			postoffice,thana,district,phone_reg,phone_off,DATE_FORMAT(dateofadmission,'%d-%m-%Y') dateofadmission,co_cur_activities,ssc_board,ssc_year,ssc_group,ssc_reg_no,
			ssc_reg_year,ssc_centre,ssc_roll,ssc_gpa,ssc_opt,ssc_school,
			hsc_board,hsc_year,hsc_group,hsc_reg_no,hsc_reg_year,hsc_centre,
			hsc_roll,hsc_gpa,hsc_opt,hsc_medium
			from student st,education edu
			where st.student_id=edu.student_id
    		and st.academic_session=edu.academic_session
    	    and st.student_id='".$student_id."'
    		and st.academic_session='".$academic_session."'
			order by st.student_id";
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }  
    public function  get_std_general_info_limit($academic_session,$group_id,$Limitstart,$limitNo)
    {
    	$sql="select st.student_id,group_id,student_name,st.academic_session,
			religion,mother_lang,DATE_FORMAT(dob,'%d-%m-%Y') dob ,fathername,mothername,permanentadd,presentaddress,village,
			postoffice,thana,district,phone_reg,phone_off,DATE_FORMAT(dateofadmission,'%d-%m-%Y') dateofadmission,co_cur_activities,ssc_board,ssc_year,ssc_group,ssc_reg_no,
			ssc_reg_year,ssc_centre,ssc_roll,ssc_gpa,ssc_opt,ssc_school,
			hsc_board,hsc_year,hsc_group,hsc_reg_no,hsc_reg_year,hsc_centre,
			hsc_roll,hsc_gpa,hsc_opt,hsc_medium
			from student st,education edu,(select student_id,academic_session from student where group_id='".$group_id."' and academic_session='".$academic_session."' order by student_id asc limit ".$Limitstart." , ".$limitNo.") s
			where st.student_id=edu.student_id
    		and st.academic_session=edu.academic_session
			and st.student_id=s.student_id
			and st.academic_session=s.academic_session
    		and st.group_id='".$group_id."'
    		and st.academic_session='".$academic_session."'
			order by st.student_id";
    	$query=$this->db->query($sql);
    	return $query->result_array();
    }
    function update_exam_marks($student_id,$academic_session, $subject_id, $data)
    {
		/*
		$sql="update subj_marks_detail set
		f_y_1st_att = ".$data['f_y_1st_att']."
		where student_id = '".$student_id."' and session_id='".$academic_session."' and subject_id='".$subject_id."'";	
		error_log($sql, 3, "my-errors.log");
		$query = $this->db->query($sql);
		*/
    	
		//$this->db->where('student_id', $student_id);
		//$this->db->where('academic_session', $academic_session);
		//$this->db->where('subject_id', $subject_id);
		
		$WhereArray = array('student_id' => $student_id, 'academic_session' => $academic_session, 'subject_id' => $subject_id);
                $this->db->where($WhereArray); 
		$this->db->update('subj_marks_detail', $data);
		$report = array();
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report !== 0){
			return true;
		}else{
			return false;
		}
	}
	
	
	function insert_std_general_info($data)
	{
	    $insert = $this->db->insert('student', $data);
	    return $insert;
	    //return mysql_insert_id();
	    //mysql_insert_id(&mysql);
	}
	function insert_std_edu_info($data)
	{
		$insert = $this->db->insert('education', $data);
		return $insert;
	}
	function insert_std_exam_merit($data)
	{
		$insert = $this->db->insert('std_exam_merit', $data);
		return $insert;
	}
	function insert_new_subject($data)
	{
		$insert = $this->db->insert('subjects', $data);
		return $insert;
	}
	function update_std_general_info($student_id,$academic_session,$data)
	{
		$this->db->where('student_id', $student_id);
		$this->db->where('academic_session', $academic_session);
		$update=$this->db->update('student', $data);
		return $update;
	}
	function update_std_edu_info($student_id,$academic_session,$data)
	{
		$this->db->where('student_id', $student_id);
		$this->db->where('academic_session', $academic_session);
		$update=$this->db->update('education', $data);
		return $update;
	}
	
	//////////////////////////////////////////////
	function first_term_result_process($exam_name,$academic_session,$group_id)
	{
		$section=substr($academic_session,0,4);
		$is_even=$section%2;
		$passMark=33;
		$stdLike="";
		if($group_id=="Science")
		{
			$passMark=40;
			if($is_even==0)
			   $stdLike="6%";
			else 
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			$passMark=35;
			
			if($is_even==0)
				$stdLike="2%";
			else
			  $stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			$passMark=35;
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
			
		$success=true;
        $passMark=$passMark-1;
		
		/*
		$sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_f_y_1_t=
			 if(
                 if((smd.f_y_1st_ct/stm.f_y_1st_ct)*100>".$passMark.",1,0) AND 
                 if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or (smd.f_y_1st_ht_mcq/stm.f_y_1st_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy'  or (smd.f_y_1st_ht_cq/stm.f_y_1st_ht_cq)*100>".$passMark."),1,0) AND 
			     if((smd.f_y_1st_ht_total/stm.f_y_1st_ht_total)*100>".$passMark.",1,0) AND
                 if((smd.f_y_1st_gran_total/stm.f_y_1st_gran_total)*100>".$passMark.",1,0)
			 ,1,0)  
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
			and smd.academic_session='".$academic_session."'";
		*/
		
		$sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_f_y_1_t=
			 if(
                 if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.f_y_1st_ht_mcq/stm.f_y_1st_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta'  or (smd.f_y_1st_ht_cq/stm.f_y_1st_ht_cq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta'  or (smd.f_y_1st_ht_total/stm.f_y_1st_ht_total)*100>".$passMark."),1,0) AND
                 if((smd.f_y_1st_gran_total/stm.f_y_1st_gran_total)*100>".$passMark.",1,0)
			 ,1,0)
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
		    and smd.student_id like '".$stdLike."'
			and smd.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		///Calculate who are pass/fail and update
		//this sql will retrive one (only pass or only fail) or two rows for each, if he has two row he is fail but next sql will update the fail
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session, is_pass_f_y_1_t from
			(select student_id,academic_session, is_pass_f_y_1_t
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_f_y_1_t
			 )tmp1
			 group by student_id,academic_session,is_pass_f_y_1_t
             having count(*)=1
			)tmp2
			set sem.first_term_is_pass=tmp2.is_pass_f_y_1_t
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session";
		/*//this sql is perfect but need not user
		 $sql="update std_exam_merit sem,
		( select tm1.student_id,tm1.academic_session,tm2.is_pass_f_y_1_t from
				(select student_id,academic_session from
						(select student_id,academic_session, is_pass_f_y_1_t
								from subj_marks_detail
								where academic_session='".$academic_session."'
								and student_id like '".$stdLike."'
								group by student_id,academic_session,is_pass_f_y_1_t
					 )tmp1
					 group by student_id,academic_session
						having count(*)=1
				)tm1,
				(select student_id,academic_session,is_pass_f_y_1_t from
						(select student_id,academic_session, is_pass_f_y_1_t
								from subj_marks_detail
								where academic_session='".$academic_session."'
								and student_id like '".$stdLike."'
								group by student_id,academic_session,is_pass_f_y_1_t
					 )tmp1
					 group by student_id,academic_session,is_pass_f_y_1_t
						having count(*)=1
				)tm2
				where tm1.academic_session=tm2.academic_session
				and tm1.student_id=tm2.student_id
		)tmp2
		set sem.first_term_is_pass=tmp2.is_pass_f_y_1_t
		where sem.student_id=tmp2.student_id
		and sem.academic_session=tmp2.academic_session";
		*/
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		///Calculate who are only fail and update
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session
			from(
			 select student_id,academic_session, is_pass_f_y_1_t
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_f_y_1_t
			 )tmp
			group by student_id,academic_session
			having count(*)>1
			)tmp2
			set sem.first_term_is_pass=0
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session
			and sem.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		//Calculate Total marks for every students
		$sql="update std_exam_merit sem,(select student_id,academic_session,sum(if(f_y_1st_gran_total<0,0,f_y_1st_gran_total)) first_term_marks 
            from (select student_id,academic_session,subject_id,
			 if(is_opt=1,f_y_1st_gran_total-40,f_y_1st_gran_total) f_y_1st_gran_total 
			from subj_marks_detail
		    where student_id like '".$stdLike."'
			and academic_session='".$academic_session."'
		    ) subj_marks_detail_tmp
			group by student_id,academic_session
			order by first_term_marks desc)tmp
			set sem.first_term_marks=tmp.first_term_marks
			where sem.student_id=tmp.student_id
			and sem.academic_session=tmp.academic_session
			and sem.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		//deduct from total mark for 4th subject who are not pass in all subject
		$sql="update std_exam_merit sem,(
			select tmp.student_id,tmp.academic_session,smd.subject_id,f_y_1st_gran_total,(f_y_1st_gran_total-40) extraMarks from
			(
			select * from std_exam_merit 
			where first_term_is_pass=0  
			and student_id like '".$stdLike."'
			and academic_session='".$academic_session."'
			)tmp,subj_marks_detail smd
			where tmp.student_id=smd.student_id
			and tmp.academic_session=smd.academic_session
			and smd.is_opt=1
		    and smd.f_y_1st_gran_total>40
		    )tmp2
			set sem.first_term_marks=(sem.first_term_marks-tmp2.extraMarks)
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session
			and tmp2.extraMarks>0
			and sem.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		


		///make the meril null for the session and student group
		$sql_merit="update std_exam_merit  set first_term_merit=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		
		
		
		///Calculate merit who are pass only for Science 
		$sql="update std_exam_merit sem,
				(
				select student_id,academic_session,first_term_marks,@rownum := @rownum + 1 AS rank
				from (
				select student_id,academic_session,first_term_marks
				from std_exam_merit
				where first_term_is_pass=1
				and academic_session='".$academic_session."'
				and student_id like '".$stdLike."'
				group by student_id,academic_session
				order by first_term_marks desc) tmp,(SELECT @rownum := 0)r
				)tmp2
				set sem.first_term_merit=tmp2.rank
				where sem.student_id=tmp2.student_id
				and sem.academic_session=tmp2.academic_session
				and sem.academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		/// merit 0 who are fail
		$sql="update std_exam_merit 
			  set first_term_merit=null
			  where first_term_is_pass=0
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		

		
		///make the tide null for the session and student group
		$sql_merit="update std_exam_merit set first_term_tied=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		$sql="select sem.first_term_marks,count(*) from std_exam_merit sem,student st
			where sem.student_id=st.student_id
			and sem.academic_session=st.academic_session
			and st.group_id='".$group_id."'
			and sem.academic_session='".$academic_session."'
			and sem.first_term_is_pass=1	
			group by sem.first_term_marks having count(*)>1";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		

		
		foreach( $query->result_array() as $row )
		{
			$inner_sql="select min(first_term_merit) first_term_merit from std_exam_merit 
						where academic_session='".$academic_session."'
						and student_id like '".$stdLike."'
						and first_term_marks=".$row['first_term_marks'];
			$inner_query=$this->db->query($inner_sql);
			foreach( $inner_query->result_array() as $inner_row )
			{
				$same_merit_sql="update std_exam_merit
				  set first_term_merit=".$inner_row['first_term_merit'].",
				  		first_term_tied='*'
				  where first_term_marks=".$row['first_term_marks']."
				  and student_id like '".$stdLike."'
				  and academic_session='".$academic_session."'
				   and first_term_is_pass=1";
				$query=$this->db->query($same_merit_sql);
			}
		}
		return $success;
	}
	////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////
	function promotion_test_result_process($exam_name,$academic_session,$group_id)
	{
	$section=substr($academic_session,0,4);
		$is_even=$section%2;
		$passMark=33;
		$stdLike="";
		if($group_id=="Science")
		{
			$passMark=40;
			if($is_even==0)
			   $stdLike="6%";
			else 
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			$passMark=35;
			
			if($is_even==0)
				$stdLike="2%";
			else
			  $stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			$passMark=35;
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
		$success=true;
        $passMark=$passMark-1;
		
       /*
        //pass with practical
        $sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_f_y_pro=
			 if(
                 if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.f_y_pro_ht_mcq/stm.f_y_pro_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta'  or (smd.f_y_pro_ht_cq/stm.f_y_pro_ht_cq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='phy' or smd.subject_id='che'), if((smd.f_y_pro_ht_prac/stm.f_y_pro_ht_prac)*100>".$passMark.",1,0),1) AND
                 if((smd.f_y_pro_ht_total/stm.f_y_pro_ht_total)*100>".$passMark.",1,0)
			 ,1,0)
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
		    and smd.student_id like '".$stdLike."'
			and smd.academic_session='".$academic_session."'";
        */
		
        /* 
         // pervious year rule
		$sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_f_y_pro=
			 if(
                 if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.f_y_pro_ht_mcq/stm.f_y_pro_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta'  or (smd.f_y_pro_ht_cq/stm.f_y_pro_ht_cq)*100>".$passMark."),1,0) AND
			     if((smd.f_y_pro_ht_total/stm.f_y_pro_ht_total)*100>".$passMark.",1,0)
			 ,1,0)
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
		    and smd.student_id like '".$stdLike."'
			and smd.academic_session='".$academic_session."'";
		
        */
        $sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_f_y_pro=
			 if(
                 if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='psy' or smd.subject_id='sta' or (smd.f_y_pro_ht_mcq/stm.f_y_pro_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='math' or smd.subject_id='psy' or smd.subject_id='sta' or (smd.f_y_pro_ht_cq/stm.f_y_pro_ht_cq)*100>".$passMark."),1,0) AND
			     if((smd.f_y_pro_ht_total/stm.f_y_pro_ht_total)*100>".$passMark.",1,0)
			 ,1,0)
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
		    and smd.student_id like '".$stdLike."'
			and smd.academic_session='".$academic_session."'";
        
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		///Calculate who are pass/fail and update
		//this sql will retrive one (only pass or only fail) or two rows for each, if he has two row he is fail but next sql will update the fail
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session, is_pass_f_y_pro from
			(select student_id,academic_session, is_pass_f_y_pro
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_f_y_pro
			 )tmp1
			 group by student_id,academic_session,is_pass_f_y_pro
             having count(*)=1
			)tmp2
			set sem.pro_test_is_pass=tmp2.is_pass_f_y_pro
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		///Calculate who are only fail and update
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session
			from(
			 select student_id,academic_session, is_pass_f_y_pro
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_f_y_pro
			 )tmp
			group by student_id,academic_session
			having count(*)>1
			)tmp2
			set sem.pro_test_is_pass=0
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session
			and sem.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		//Calculate Total marks for every students
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session,sum(if(f_y_pro_ht_total<0,0,f_y_pro_ht_total)) pro_test_marks
            from (
				select student_id,academic_session,subject_id,
			    if(is_opt=1,f_y_pro_ht_total-40,f_y_pro_ht_total) f_y_pro_ht_total
			    from subj_marks_detail
		        where student_id like '".$stdLike."'
			    and academic_session='".$academic_session."'
		      ) subj_marks_detail_tmp
			group by student_id,academic_session
			order by pro_test_marks desc)tmp
			set sem.pro_test_marks=tmp.pro_test_marks
			where sem.student_id=tmp.student_id
			and sem.academic_session=tmp.academic_session
			and sem.academic_session='".$academic_session."'";
	
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		

		//deduct from total mark for 4th subject who are not pass in all subject
		$sql="update std_exam_merit sem,(
			select tmp.student_id,tmp.academic_session,smd.subject_id,f_y_pro_ht_total,(f_y_pro_ht_total-40) extraMarks from
			(
			select * from std_exam_merit
			where pro_test_is_pass=0
			and student_id like '".$stdLike."'
			and academic_session='".$academic_session."'
			)tmp,subj_marks_detail smd
			where tmp.student_id=smd.student_id
			and tmp.academic_session=smd.academic_session
			and smd.is_opt=1
		    and smd.f_y_pro_ht_total>40
		    )tmp2
			set sem.pro_test_marks=(sem.pro_test_marks-tmp2.extraMarks)
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session
			and tmp2.extraMarks>0
			and sem.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		

		///make the meril null for the session and student group
		$sql_merit="update std_exam_merit  set pro_test_merit=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		
		
		///Calculate merit who are pass 
		$sql="update std_exam_merit sem,
				(
				select student_id,academic_session,pro_test_marks,@rownum := @rownum + 1 AS rank
				from (
				select student_id,academic_session,pro_test_marks
				from std_exam_merit
				where pro_test_is_pass=1
				and academic_session='".$academic_session."'
				and student_id like '".$stdLike."'
				group by student_id,academic_session
				order by pro_test_marks desc) tmp,(SELECT @rownum := 0)r
				)tmp2
				set sem.pro_test_merit=tmp2.rank
				where sem.student_id=tmp2.student_id
				and sem.academic_session=tmp2.academic_session
				and sem.academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		/// Calculate GPA who are pass and core subject
		$sql="update subj_marks_detail set f_y_pro_gpa=if(f_y_pro_ht_total>=80,5,if(f_y_pro_ht_total>=70,4,if(f_y_pro_ht_total>=60,3.5,if(f_y_pro_ht_total>=50,3,if(f_y_pro_ht_total>=40,2,if(f_y_pro_ht_total>=33,1,0))))))  
			  where  is_opt is null
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		/// Calculate GPA who are pass and optional subject
		$sql="update subj_marks_detail set f_y_pro_gpa=if(f_y_pro_ht_total>=80,3,if(f_y_pro_ht_total>=70,2,if(f_y_pro_ht_total>=60,1.5,if(f_y_pro_ht_total>=50,1,0))))
			  where is_opt='1'
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		//Calculate average GPA for every students
		$sql="update std_exam_merit sem,
			(
				select student_id,academic_session,if(round(sum(f_y_pro_gpa)/6,1)>5,5,round(sum(f_y_pro_gpa)/6,1)) gpa
	            from subj_marks_detail
				where student_id like '".$stdLike."'
			    and academic_session='".$academic_session."'
	            group by student_id,academic_session
		        
		      )tmp
			set sem.pro_test_gpa=tmp.gpa
			where sem.student_id=tmp.student_id
			and sem.academic_session=tmp.academic_session
			and sem.academic_session='".$academic_session."'";
		
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		/// merit 0 who are fail
		$sql="update std_exam_merit
			  set pro_test_merit=null
			  where pro_test_is_pass=0
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		
		///make the tide null for the session and student group
		$sql_merit="update std_exam_merit set pro_test_tied=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		
		$sql="select sem.pro_test_marks,count(*) from std_exam_merit sem,student st
			where sem.student_id=st.student_id
			and sem.academic_session=st.academic_session
			and st.group_id='".$group_id."'
			and sem.academic_session='".$academic_session."'
			and sem.pro_test_is_pass=1
			group by sem.pro_test_marks having count(*)>1";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		

		foreach( $query->result_array() as $row )
		{

			$inner_sql="select min(sem.pro_test_merit) pro_test_merit from std_exam_merit sem,student st
						where sem.academic_session=st.academic_session 
					    and sem.student_id=st.student_id 
					    and sem.academic_session='".$academic_session."'
						and st.student_id like '".$stdLike."'
						and pro_test_marks=".$row['pro_test_marks'];
			
			$inner_query=$this->db->query($inner_sql);
			foreach( $inner_query->result_array() as $inner_row )
			{
				$same_merit_sql="update std_exam_merit
				  set pro_test_merit=".$inner_row['pro_test_merit'].",
				  		pro_test_tied='*'
				  where pro_test_marks=".$row['pro_test_marks']."
				  and student_id like '".$stdLike."'
				  and academic_session='".$academic_session."'
				   and pro_test_is_pass=1";
				$query=$this->db->query($same_merit_sql);
			}
		}
		
	
		
		return $success;
	}
	////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////
	function pre_test_result_process($exam_name,$academic_session,$group_id)
	{
	$section=substr($academic_session,0,4);
		$is_even=$section%2;
		$passMark=33;
		$stdLike="";
		if($group_id=="Science")
		{
			$passMark=40;
			if($is_even==0)
			   $stdLike="6%";
			else 
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			$passMark=35;
			
			if($is_even==0)
				$stdLike="2%";
			else
			  $stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			$passMark=35;
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
			
		$success=true;
        $passMark=$passMark-1;
	
		$sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_s_y_pre=
			 if(
                 if((smd.s_y_pre_ct/stm.s_y_pre_ct)*100>".$passMark.",1,0) AND
                 if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_pre_ht_mcq/stm.s_y_pre_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_pre_ht_cq/stm.s_y_pre_ht_cq)*100>".$passMark."),1,0) AND
			     if((smd.s_y_pre_ht_total/stm.s_y_pre_ht_total)*100>".$passMark.",1,0) AND
                 if((smd.s_y_pre_gran_total/stm.s_y_pre_gran_total)*100>".$passMark.",1,0)
			 ,1,0)
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
			and smd.student_id like '".$stdLike."'
			and smd.academic_session='".$academic_session."'";
		
		
		$sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_s_y_pre=
			 if(
                 if((1/1)*100>".$passMark.",1,0) AND
                 if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_pre_ht_mcq/stm.s_y_pre_ht_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_pre_ht_cq/stm.s_y_pre_ht_cq)*100>".$passMark."),1,0) AND
			     if((smd.s_y_pre_ht_total/stm.s_y_pre_ht_total)*100>".$passMark.",1,0) AND
                 if((smd.s_y_pre_gran_total/stm.s_y_pre_gran_total)*100>".$passMark.",1,0)
			 ,1,0)
			where smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
			and smd.student_id like '".$stdLike."'
			and smd.academic_session='".$academic_session."'";
		
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		//Calculate Total marks for every students
		$sql="update std_exam_merit sem,(select student_id,academic_session,sum(if(s_y_pre_gran_total<0,0,s_y_pre_gran_total)) pre_test_marks
            from (select student_id,academic_session,subject_id,
			 if(is_opt=1,s_y_pre_gran_total-40,s_y_pre_gran_total) s_y_pre_gran_total
			from subj_marks_detail
		    where student_id like '".$stdLike."'
			and academic_session='".$academic_session."'
		    ) subj_marks_detail_tmp
			group by student_id,academic_session
			order by pre_test_marks desc)tmp
			set sem.pre_test_marks=tmp.pre_test_marks
			where sem.student_id=tmp.student_id
			and sem.student_id like '".$stdLike."'
			and sem.academic_session=tmp.academic_session
			and sem.academic_session='".$academic_session."'";
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	

	
		///make the meril null for the session and student group
		$sql_merit="update std_exam_merit  set pre_test_merit=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		///Calculate who are pass/fail and update
		//this sql will retrive one(only pass only fail) or two rows for each, if he has two row he is fail but next sql will update the fail
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session, is_pass_s_y_pre from
			(select student_id,academic_session, is_pass_s_y_pre
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_s_y_pre
			 )tmp1
			 group by student_id,academic_session,is_pass_s_y_pre
             having count(*)=1
			)tmp2
			set sem.pre_test_is_pass=tmp2.is_pass_s_y_pre
			where sem.student_id=tmp2.student_id
			and sem.student_id like '".$stdLike."'
			and sem.academic_session=tmp2.academic_session
			and sem.academic_session='".$academic_session."'";
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		///Calculate who are only fail and update
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session
			from(
			 select student_id,academic_session, is_pass_s_y_pre
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_s_y_pre
			 )tmp
			group by student_id,academic_session
			having count(*)>1
			)tmp2
			set sem.pre_test_is_pass=0
			where sem.student_id=tmp2.student_id
			and sem.student_id like '".$stdLike."'
			and sem.academic_session=tmp2.academic_session
			and sem.academic_session='".$academic_session."'";
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		///Calculate merit who are pass only for Science
		$sql="update std_exam_merit sem,
				(
				select student_id,academic_session,pre_test_marks,@rownum := @rownum + 1 AS rank
				from (
				select student_id,academic_session,pre_test_marks
				from std_exam_merit
				where pre_test_is_pass=1
				and academic_session='".$academic_session."'
				and student_id like '".$stdLike."'
				group by student_id,academic_session
				order by pre_test_marks desc) tmp,(SELECT @rownum := 0)r
				)tmp2
				set sem.pre_test_merit=tmp2.rank
				where sem.student_id=tmp2.student_id
				and sem.student_id like '".$stdLike."'
				and sem.academic_session=tmp2.academic_session
				and sem.academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		/// merit 0 who are fail
		$sql="update std_exam_merit
			  set pre_test_merit=null
			  where pre_test_is_pass=0
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		
		///make the tide null for the session and student group
		$sql_merit="update std_exam_merit  set pre_test_tied=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
	
		$sql="select sem.pre_test_marks,count(*) from std_exam_merit sem,student st
			where sem.student_id=st.student_id
			and sem.academic_session=st.academic_session
			and st.group_id='".$group_id."'
			and sem.academic_session='".$academic_session."'
			and sem.pre_test_is_pass=1
			group by sem.pre_test_marks having count(*)>1";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
	
	
		foreach( $query->result_array() as $row )
		{
			$inner_sql="select min(sem.pre_test_merit) pre_test_merit from std_exam_merit sem,student st
						where sem.academic_session=st.academic_session
						and st.group_id='".$group_id."'
						and pre_test_marks=".$row['pre_test_marks'];
			$inner_query=$this->db->query($inner_sql);
			foreach( $inner_query->result_array() as $inner_row )
			{
				$same_merit_sql="update std_exam_merit
				  set pre_test_merit=".$inner_row['pre_test_merit'].",
				  		pre_test_tied='*'
				  where pre_test_marks=".$row['pre_test_marks']."
				  and student_id like '".$stdLike."'
				  and academic_session='".$academic_session."'
				   and pre_test_is_pass=1";
				$query=$this->db->query($same_merit_sql);
				
			}
		}
		return $success;
	}
	///////////////////////////////////////////////////////////
	//////////////////////////////////////////////
	function test_exam_result_process($exam_name,$academic_session,$group_id)
	{
	   $section=substr($academic_session,0,4);
		$is_even=$section%2;
		$passMark=33;
		$stdLike="";
		if($group_id=="Science")
		{
			$passMark=40;
			if($is_even==0)
			   $stdLike="6%";
			else 
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			$passMark=35;
			
			if($is_even==0)
				$stdLike="2%";
			else
			  $stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			$passMark=35;
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
			
		$success=true;
        $passMark=$passMark-1;
		$success=true;
	
		$sql="update subj_marks_detail smd,sub_exam_total_marks stm
			set is_pass_s_y_test=
			 if(
				 (
				 if((smd.subject_id='eng'  or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_t_p1_mcq/stm.s_y_t_p1_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng'  or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_t_p1_cq/stm.s_y_t_p1_cq)*100>".$passMark."),1,0) AND
                 if((smd.s_y_t_p1_total/stm.s_y_t_p1_total)*100>".$passMark.",1,0) AND
                 if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_t_p2_mcq/stm.s_y_t_p2_mcq)*100>".$passMark."),1,0) AND
			     if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta' or (smd.s_y_t_p2_cq/stm.s_y_t_p2_cq)*100>".$passMark."),1,0) AND		
                 if((smd.s_y_t_p2_total/stm.s_y_t_p2_total)*100>".$passMark.",1,0)
                 ) OR
                 if((smd.subject_id='eng' or smd.subject_id='ben' or smd.subject_id='math' or smd.subject_id='ict' or smd.subject_id='eco' or smd.subject_id='log' or smd.subject_id='geo' or smd.subject_id='psy' or smd.subject_id='fbi' or smd.subject_id='sta'),if((smd.s_y_test_gra_total/stm.s_y_test_gra_total)*100>".$passMark.",1,0),0)		
                 		
			 ,1,0)
			where smd.student_id like '".$stdLike."'
            and smd.subject_id=stm.subject_id
			and stm.group_id='".$group_id."'
			and smd.academic_session='".$academic_session."'";
		     
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		//Calculate Total marks for every students
		$sql="update std_exam_merit sem,(select student_id,academic_session,sum(if(s_y_test_gra_total<0,0,s_y_test_gra_total)) test_exam_marks
            from (select student_id,academic_session,subject_id,
			 if(is_opt=1,s_y_test_gra_total-80,s_y_test_gra_total) s_y_test_gra_total
			from subj_marks_detail
		    where student_id like '".$stdLike."'
			and academic_session='".$academic_session."'
		    ) subj_marks_detail_tmp
			group by student_id,academic_session
			order by test_exam_marks desc)tmp
			set sem.test_exam_marks=tmp.test_exam_marks
			where sem.student_id=tmp.student_id
			and sem.academic_session=tmp.academic_session
			and sem.academic_session='".$academic_session."'";
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;

		///make the Merit null for the session and student group
		$sql_merit="update std_exam_merit set test_exam_merit=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
	
		///Calculate who are pass/fail and update
		//this sql will retrive one(only pass only fail) or two rows for each, if he has two row he is fail but next sql will update the fail
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session, is_pass_s_y_test from
			(select student_id,academic_session, is_pass_s_y_test
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_s_y_test
			 )tmp1
			 group by student_id,academic_session,is_pass_s_y_test
             having count(*)=1
			)tmp2
			set sem.test_exam_is_pass=tmp2.is_pass_s_y_test
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session
			and sem.academic_session='".$academic_session."'";
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		///Calculate who are only fail and update
		$sql="update std_exam_merit sem,
			(
			select student_id,academic_session
			from(
			 select student_id,academic_session, is_pass_s_y_test
			 from subj_marks_detail
			 where academic_session='".$academic_session."'
			 and student_id like '".$stdLike."'
			 group by student_id,academic_session,is_pass_s_y_test
			 )tmp
			group by student_id,academic_session
			having count(*)>1
			)tmp2
			set sem.test_exam_is_pass=0
			where sem.student_id=tmp2.student_id
			and sem.academic_session=tmp2.academic_session
			and sem.academic_session='".$academic_session."'";
	
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		///Calculate merit who are pass
		$sql="update std_exam_merit sem,
				(
				select student_id,academic_session,test_exam_marks,@rownum := @rownum + 1 AS rank
				from (
				select student_id,academic_session,test_exam_marks
				from std_exam_merit
				where test_exam_is_pass=1
				and academic_session='".$academic_session."'
				and student_id like '".$stdLike."'
				group by student_id,academic_session
				order by test_exam_marks desc) tmp,(SELECT @rownum := 0)r
				)tmp2
				set sem.test_exam_merit=tmp2.rank
				where sem.student_id=tmp2.student_id
				and sem.academic_session=tmp2.academic_session
				and sem.academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		
		/// Calculate GPA who are pass and core subject
		$sql="update subj_marks_detail set s_y_test_gpa=if(s_y_test_gra_total>=160,5,if(s_y_test_gra_total>=140,4,if(s_y_test_gra_total>=120,3.5,if(s_y_test_gra_total>=100,3,if(s_y_test_gra_total>=80,2,if(s_y_test_gra_total>=66,1,0))))))
			  where  is_opt is null
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		

		/// Calculate GPA only for ICT
		$sql="update subj_marks_detail set s_y_test_gpa=if(s_y_test_gra_total>=80,5,if(s_y_test_gra_total>=70,4,if(s_y_test_gra_total>=60,3.5,if(s_y_test_gra_total>=50,3,if(s_y_test_gra_total>=40,2,if(s_y_test_gra_total>=33,1,0))))))
			  where  subject_id='ict'
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		/// Calculate GPA who are pass and optional subject
		$sql="update subj_marks_detail set s_y_test_gpa=if(s_y_test_gra_total>=160,3,if(s_y_test_gra_total>=140,2,if(s_y_test_gra_total>=120,1.5,if(s_y_test_gra_total>=100,1,0))))
			  where is_opt='1'
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
		
		
		
		//Calculate average GPA for every students
		$sql="update std_exam_merit sem,
			(
				select student_id,academic_session,if(round(sum(s_y_test_gpa)/6,1)>5,5,round(sum(s_y_test_gpa)/6,1)) gpa
	            from subj_marks_detail
				where student_id like '".$stdLike."'
			    and academic_session='".$academic_session."'
	            group by student_id,academic_session
		
		      )tmp
			set sem.test_exam_gpa=tmp.gpa
			where sem.student_id=tmp.student_id
			and sem.academic_session=tmp.academic_session
			and sem.academic_session='".$academic_session."'";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
	
		/// merit 0 who are fail
		$sql="update std_exam_merit
			  set test_exam_merit=null
			  where test_exam_is_pass=0
			  and student_id like '".$stdLike."'
			  and academic_session='".$academic_session."'";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
		
		///make the tide null for the session and student group
		$sql_merit="update std_exam_merit  set test_exam_tied=null
				where  academic_session='".$academic_session."'
				and student_id like '".$stdLike."'";
		$query=$this->db->query($sql_merit);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		
	
		$sql="select sem.test_exam_marks,count(*) from std_exam_merit sem,student st
			where sem.student_id=st.student_id
			and sem.academic_session=st.academic_session
			and st.group_id='".$group_id."'
			and sem.academic_session='".$academic_session."'
			and sem.test_exam_is_pass=1
			group by sem.test_exam_marks having count(*)>1";
		$query=$this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
	
	
	
		foreach( $query->result_array() as $row )
		{
			$inner_sql="select min(sem.test_exam_merit) test_exam_merit from std_exam_merit sem,student st
						where sem.academic_session=st.academic_session
						and st.group_id='".$group_id."'
						and test_exam_marks=".$row['test_exam_marks'];
			$inner_query=$this->db->query($inner_sql);
			foreach( $inner_query->result_array() as $inner_row )
			{
				$same_merit_sql="update std_exam_merit
				  set test_exam_merit=".$inner_row['test_exam_merit'].",
				  		test_exam_tied='*'
				  where test_exam_marks=".$row['test_exam_marks']."
				  and student_id like '".$stdLike."'
				  and academic_session='".$academic_session."'
				   and test_exam_is_pass=1";
				$query=$this->db->query($same_merit_sql);
				
			}
		}
		return $success;
	}
	////////////////////////////////////////////////////////////////////
	function get_std_exam_merit($academic_session,$group_id)
	{
		$sql="select sem.student_id,first_term_marks,sem.first_term_merit,sem.first_term_tied,
			pro_test_marks, pro_test_merit,pro_test_tied,pro_test_gpa,
			pre_test_marks,	pre_test_merit,pre_test_tied,
			test_exam_marks,test_exam_merit,test_exam_tied,test_exam_gpa
			from std_exam_merit sem,student st
			where sem.student_id=st.student_id
			and sem.academic_session=st.academic_session
			and sem.academic_session='".$academic_session."'
			and st.group_id='".$group_id."'";
		$query=$this->db->query($sql);
		$data=array();
		foreach( $query->result_array() as $row )
		{
			$student_id=$row['student_id'];
			$data[$student_id]['first_term_marks']=$row['first_term_marks'];
			$data[$student_id]['first_term_merit']=$row['first_term_merit']==null ?'Nil':$row['first_term_merit'];
			$data[$student_id]['first_term_tied']=$row['first_term_tied'];
			
			$data[$student_id]['pro_test_marks']=$row['pro_test_marks'];
			$data[$student_id]['pro_test_gpa']=$row['pro_test_gpa'];
			if($row['pro_test_marks']==null || $data[$student_id]['pro_test_marks']==0)
			 $data[$student_id]['pro_test_merit']=null;
			else
			 $data[$student_id]['pro_test_merit']=$row['pro_test_merit']==null ?'Nil':$row['pro_test_merit'];
			$data[$student_id]['pro_test_tied']=$row['pro_test_tied'];
			
			$data[$student_id]['pre_test_marks']=$row['pre_test_marks'];
			if($row['pre_test_marks']==null || $data[$student_id]['pre_test_marks']==0)
			 $data[$student_id]['pre_test_merit']=null;
			else
			 $data[$student_id]['pre_test_merit']=$row['pre_test_merit']==null ?'Nil':$row['pre_test_merit'];
			$data[$student_id]['pre_test_tied']=$row['pre_test_tied'];
			
			$data[$student_id]['test_exam_marks']=$row['test_exam_marks'];
			$data[$student_id]['test_exam_gpa']=$row['test_exam_gpa'];
			if($row['test_exam_marks']==null || $data[$student_id]['test_exam_marks']==0)
			 $data[$student_id]['test_exam_merit']=null;
			else
			 $data[$student_id]['test_exam_merit']=$row['test_exam_merit']==null ?'X':$row['test_exam_merit'];
			$data[$student_id]['test_exam_tied']=$row['test_exam_tied'];
		}
		return $data;
	}
	/////////////////////////////////////////////////////////
	function insert_std_core_subject($academic_session,$group_id)
	{
		$success=true;
		$sql="insert into subj_marks_detail(student_id,academic_session,subject_id )(
				select student_id,academic_session,subject_id from student st,subjects su
				where academic_session='".$academic_session."'
				and is_core='1'
				and st.group_id='".$group_id."'
				and st.group_id=su.group_id
				order by student_id,subject_id
				)";
		
		$query = $this->db->query($sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		return $success;
	}
	///////////////////////////////////////////
	function insert_std_subject($data)
	{
		$insert = $this->db->insert('subj_marks_detail', $data);
		return $insert;
		//return mysql_insert_id();
		//mysql_insert_id(&mysql);
	}
	////////////////////////////////////////////
	 function get_subject($core=null)
	 {
	 	$sql="select subject_id,subject_name, group_id,subject_order from subjects";
	 	if($core!=null)
	 	{
			$sql.=' where is_core='.$core;
	 	}
		$sql.=" order by group_id,subject_order";
	 	$query=$this->db->query($sql);
	 	return $query->result_array();
	 }
	/////////////////////////////////////////////
	function get_academic_session()
	{
		 
		$sql="select distinct academic_session from student order by academic_session desc";
		$query=$this->db->query($sql);
		return $query->result_array();
	}
	//////////////////////////////////////
	function get_exam_marks_first_term($academic_session,$group_id)
	{
		
		$section=substr($academic_session,0,4);
		$is_even=$section%2;
		$stdLike="";
		if($group_id=="Science")
		{
			if($is_even==0)
				$stdLike="6%";
			else
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			if($is_even==0)
				$stdLike="2%";
			else
				$stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
		
		$sql="";
		if($group_id=="Science")
		{
		$sql="select tmp.*,sem.first_term_marks,sem.first_term_merit,sem.first_term_is_pass from 
			(select student_id,academic_session,
			sum(if(subject_id='ben',f_y_1st_gran_total,0))ben,
			sum(if(subject_id='eng',f_y_1st_gran_total,0)) eng,
			sum(if(subject_id='ict',f_y_1st_gran_total,0)) ict,
			sum(if(subject_id='phy',f_y_1st_gran_total,0)) phy, 
			sum(if(subject_id='che',f_y_1st_gran_total,0)) che,
			sum(if(subject_id='bio',f_y_1st_gran_total,0)) bio,
			sum(if(subject_id='math',f_y_1st_gran_total,0)) math
			from subj_marks_detail
			where academic_session='".$academic_session."'
			and student_id like '".$stdLike."'
			group by student_id)tmp,std_exam_merit sem
            where tmp.academic_session=sem.academic_session
            and tmp.student_id=sem.student_id";
		}
		if($group_id=="Humanities")
		{
			$sql="select tmp.*,sem.first_term_marks,sem.first_term_merit,sem.first_term_is_pass from 
			     (select student_id,academic_session,
				sum(if(subject_id='ben',f_y_1st_gran_total,0))ben,
				sum(if(subject_id='eng',f_y_1st_gran_total,0)) eng,
				sum(if(subject_id='ict',f_y_1st_gran_total,0)) ict,
				sum(if(subject_id='civ',f_y_1st_gran_total,0)) civ, 
				sum(if(subject_id='eco',f_y_1st_gran_total,0)) eco,
				sum(if(subject_id='log',f_y_1st_gran_total,0)) log,
				sum(if(subject_id='geo',f_y_1st_gran_total,0)) geo,
				sum(if(subject_id='his',f_y_1st_gran_total,0)) his,
				sum(if(subject_id='psy',f_y_1st_gran_total,0)) psy
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		if($group_id=="Business Studies")
		{
			$sql="select tmp.*,sem.first_term_marks,sem.first_term_merit,sem.first_term_is_pass from 
			     (select student_id,academic_session,
				sum(if(subject_id='ben',f_y_1st_gran_total,0))ben,
				sum(if(subject_id='eng',f_y_1st_gran_total,0)) eng,
				sum(if(subject_id='ict',f_y_1st_gran_total,0)) ict,
				sum(if(subject_id='bom',f_y_1st_gran_total,0)) bom, 
				sum(if(subject_id='acc',f_y_1st_gran_total,0)) acc,
				sum(if(subject_id='fbi',f_y_1st_gran_total,0)) fbi,
				sum(if(subject_id='eco',f_y_1st_gran_total,0)) eco,
				sum(if(subject_id='sta',f_y_1st_gran_total,0)) sta
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		$query=$this->db->query($sql);
		return $query->result_array();
	}
	/////////////////////////////////////////////////////
	function get_exam_marks_Promotion_Test($academic_session,$group_id)
	{
	    $section=substr($academic_session,0,4);
		$is_even=$section%2;
		$stdLike="";
		if($group_id=="Science")
		{
			if($is_even==0)
				$stdLike="6%";
			else
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			if($is_even==0)
				$stdLike="2%";
			else
				$stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
		
	
		$sql="";
		if($group_id=="Science")
		{
			$sql="select tmp.*,sem.pro_test_marks,sem.pro_test_merit,sem.pro_test_gpa,sem.pro_test_is_pass from
			(select student_id,academic_session,
			sum(if(subject_id='ben',f_y_pro_ht_total,0))ben,
			sum(if(subject_id='eng',f_y_pro_ht_total,0)) eng,
			sum(if(subject_id='ict',f_y_pro_ht_total,0)) ict,
			sum(if(subject_id='phy',f_y_pro_ht_total,0)) phy,
			sum(if(subject_id='che',f_y_pro_ht_total,0)) che,
			sum(if(subject_id='bio',f_y_pro_ht_total,0)) bio,
			sum(if(subject_id='math',f_y_pro_ht_total,0)) math
			from subj_marks_detail
			where academic_session='".$academic_session."'
			and student_id like '".$stdLike."'
			group by student_id)tmp,std_exam_merit sem
            where tmp.academic_session=sem.academic_session
            and tmp.student_id=sem.student_id";
		}
		if($group_id=="Humanities")
		{
			$sql="select tmp.*,sem.pro_test_marks,sem.pro_test_merit,sem.pro_test_gpa,sem.pro_test_is_pass from
			     (select student_id,academic_session,
				sum(if(subject_id='ben',f_y_pro_ht_total,0))ben,
				sum(if(subject_id='eng',f_y_pro_ht_total,0)) eng,
				sum(if(subject_id='ict',f_y_pro_ht_total,0)) ict,
				sum(if(subject_id='civ',f_y_pro_ht_total,0)) civ,
				sum(if(subject_id='eco',f_y_pro_ht_total,0)) eco,
				sum(if(subject_id='log',f_y_pro_ht_total,0)) log,
				sum(if(subject_id='geo',f_y_pro_ht_total,0)) geo,
				sum(if(subject_id='his',f_y_pro_ht_total,0)) his,
				sum(if(subject_id='psy',f_y_pro_ht_total,0)) psy
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		if($group_id=="Business Studies")
		{
			$sql="select tmp.*,sem.pro_test_marks,sem.pro_test_merit,sem.pro_test_gpa,sem.pro_test_is_pass from
			     (select student_id,academic_session,
				sum(if(subject_id='ben',f_y_pro_ht_total,0))ben,
				sum(if(subject_id='eng',f_y_pro_ht_total,0)) eng,
				sum(if(subject_id='ict',f_y_pro_ht_total,0)) ict,
				sum(if(subject_id='bom',f_y_pro_ht_total,0)) bom,
				sum(if(subject_id='acc',f_y_pro_ht_total,0)) acc,
				sum(if(subject_id='fbi',f_y_pro_ht_total,0)) fbi,
				sum(if(subject_id='eco',f_y_pro_ht_total,0)) eco,
				sum(if(subject_id='sta',f_y_pro_ht_total,0)) sta
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		$query=$this->db->query($sql);
		return $query->result_array();
	}
	/////////////////////////////////////////////////////
	function get_exam_marks_Pre_Test($academic_session,$group_id)
	{
	   $section=substr($academic_session,0,4);
		$is_even=$section%2;
		$stdLike="";
		if($group_id=="Science")
		{
			if($is_even==0)
				$stdLike="6%";
			else
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			if($is_even==0)
				$stdLike="2%";
			else
				$stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
		
	
		$sql="";
		if($group_id=="Science")
		{
			$sql="select tmp.*,sem.pre_test_marks,sem.pre_test_merit,sem.pre_test_is_pass from
			(select student_id,academic_session,
			sum(if(subject_id='ben',s_y_pre_gran_total,0))ben,
			sum(if(subject_id='eng',s_y_pre_gran_total,0)) eng,
			sum(if(subject_id='ict',s_y_pre_gran_total,0)) ict,
			sum(if(subject_id='phy',s_y_pre_gran_total,0)) phy,
			sum(if(subject_id='che',s_y_pre_gran_total,0)) che,
			sum(if(subject_id='bio',s_y_pre_gran_total,0)) bio,
			sum(if(subject_id='math',s_y_pre_gran_total,0)) math
			from subj_marks_detail
			where academic_session='".$academic_session."'
			and student_id like '".$stdLike."'
			group by student_id)tmp,std_exam_merit sem
            where tmp.academic_session=sem.academic_session
            and tmp.student_id=sem.student_id";
		}
		if($group_id=="Humanities")
		{
			$sql="select tmp.*,sem.pre_test_marks,sem.pre_test_merit,sem.pre_test_is_pass from
			     (select student_id,academic_session,
				sum(if(subject_id='ben',s_y_pre_gran_total,0))ben,
				sum(if(subject_id='eng',s_y_pre_gran_total,0)) eng,
				sum(if(subject_id='ict',s_y_pre_gran_total,0)) ict,
				sum(if(subject_id='civ',s_y_pre_gran_total,0)) civ,
				sum(if(subject_id='eco',s_y_pre_gran_total,0)) eco,
				sum(if(subject_id='log',s_y_pre_gran_total,0)) log,
				sum(if(subject_id='geo',s_y_pre_gran_total,0)) geo,
				sum(if(subject_id='his',s_y_pre_gran_total,0)) his,
				sum(if(subject_id='psy',s_y_pre_gran_total,0)) psy
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		if($group_id=="Business Studies")
		{
			$sql="select tmp.*,sem.pre_test_marks,sem.pre_test_merit,sem.pre_test_is_pass from
			     (select student_id,academic_session,
				sum(if(subject_id='ben',s_y_pre_gran_total,0))ben,
				sum(if(subject_id='eng',s_y_pre_gran_total,0)) eng,
				sum(if(subject_id='ict',s_y_pre_gran_total,0)) ict,
				sum(if(subject_id='bom',s_y_pre_gran_total,0)) bom,
				sum(if(subject_id='acc',s_y_pre_gran_total,0)) acc,
				sum(if(subject_id='fbi',s_y_pre_gran_total,0)) fbi,
				sum(if(subject_id='eco',s_y_pre_gran_total,0)) eco,
				sum(if(subject_id='sta',s_y_pre_gran_total,0)) sta
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		$query=$this->db->query($sql);
		return $query->result_array();
	}
	/////////////////////////////////////////////////////
	function get_exam_marks_Text_exam($academic_session,$group_id)
	{
	$section=substr($academic_session,0,4);
		$is_even=$section%2;
		$stdLike="";
		if($group_id=="Science")
		{
			if($is_even==0)
				$stdLike="6%";
			else
				$stdLike="5%";
		}
		if($group_id=="Humanities")
		{
			if($is_even==0)
				$stdLike="2%";
			else
				$stdLike="1%";
		}
		if($group_id=="Business Studies")
		{
			if($is_even==0)
				$stdLike="4%";
			else
				$stdLike="3%";
		}
		
	
		$sql="";
		if($group_id=="Science")
		{
			$sql="select tmp.*,sem.test_exam_marks,sem.test_exam_merit,sem.test_exam_gpa,sem.test_exam_is_pass from
			(select student_id,academic_session,
			sum(if(subject_id='ben',s_y_pre_gran_total,0))ben,
			sum(if(subject_id='eng',s_y_pre_gran_total,0)) eng,
			sum(if(subject_id='ict',s_y_pre_gran_total,0)) ict,
			sum(if(subject_id='phy',s_y_pre_gran_total,0)) phy,
			sum(if(subject_id='che',s_y_pre_gran_total,0)) che,
			sum(if(subject_id='bio',s_y_pre_gran_total,0)) bio,
			sum(if(subject_id='math',s_y_pre_gran_total,0)) math
			from subj_marks_detail
			where academic_session='".$academic_session."'
			and student_id like '".$stdLike."'
			group by student_id)tmp,std_exam_merit sem
            where tmp.academic_session=sem.academic_session
            and tmp.student_id=sem.student_id";
		}
		if($group_id=="Humanities")
		{
			$sql="select tmp.*,sem.test_exam_marks,sem.test_exam_merit,sem.test_exam_gpa,sem.test_exam_is_pass from
			     (select student_id,academic_session,
				sum(if(subject_id='ben',s_y_pre_gran_total,0))ben,
				sum(if(subject_id='eng',s_y_pre_gran_total,0)) eng,
				sum(if(subject_id='ict',s_y_pre_gran_total,0)) ict,
				sum(if(subject_id='civ',s_y_pre_gran_total,0)) civ,
				sum(if(subject_id='eco',s_y_pre_gran_total,0)) eco,
				sum(if(subject_id='log',s_y_pre_gran_total,0)) log,
				sum(if(subject_id='geo',s_y_pre_gran_total,0)) geo,
				sum(if(subject_id='his',s_y_pre_gran_total,0)) his,
				sum(if(subject_id='psy',s_y_pre_gran_total,0)) psy
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		if($group_id=="Business Studies")
		{
			$sql="select tmp.*,sem.test_exam_marks,sem.test_exam_merit,sem.test_exam_gpa,sem.test_exam_is_pass from
			     (select student_id,academic_session,
				sum(if(subject_id='ben',s_y_pre_gran_total,0))ben,
				sum(if(subject_id='eng',s_y_pre_gran_total,0)) eng,
				sum(if(subject_id='ict',s_y_pre_gran_total,0)) ict,
				sum(if(subject_id='bom',s_y_pre_gran_total,0)) bom,
				sum(if(subject_id='acc',s_y_pre_gran_total,0)) acc,
				sum(if(subject_id='fbi',s_y_pre_gran_total,0)) fbi,
				sum(if(subject_id='eco',s_y_pre_gran_total,0)) eco,
				sum(if(subject_id='sta',s_y_pre_gran_total,0)) sta
				from subj_marks_detail
				where academic_session='".$academic_session."'
			    and student_id like '".$stdLike."'
			    group by student_id)tmp,std_exam_merit sem
                where tmp.academic_session=sem.academic_session
                and tmp.student_id=sem.student_id";
		}
		$query=$this->db->query($sql);
		return $query->result_array();
	}
	///////////////////////////////////////////////////////
	function subject_total_attendence()
	{
	
		$academic_session=$this->input->post('academic_session');
		$group_id=$this->input->post('group_id');
		$section=$this->input->post('section');
		$subject_id=$this->input->post('subject_id');
		$exam_name=$this->input->post('exam_name');
	
		if($exam_name=="first_term")
			$exam_name="f_y_1st_t_att";
		elseif ($exam_name=="pro_test")
		$exam_name="f_y_pro_t_att";
		elseif ($exam_name=="pre_test")
		$exam_name="s_y_pre_t_att";
		elseif ($exam_name=="test_exam")
		$exam_name="s_y_test_t_att";
		else {
			$exam_name="";
		}
		$sql="select ". $exam_name. " as attence from subj_attendance
				where subject_id='".$subject_id."' and group_id='".$group_id."'
				and academic_session='".$academic_session."' and section='".$section."'";
		$query=$this->db->query($sql);
		$attendence="";
		foreach( $query->result_array() as $row )
		{
			$attendence=$row['attence'];
		}
		return $attendence;
	
	}
	///////////////////////////////////////////////////////
	function get_all_attendence()
	{
	
		$academic_session=$this->input->post('academic_session');
		$group_id=$this->input->post('group_id');

		$sql="select subject_id,group_id, academic_session, section, f_y_1st_t_att, f_y_pro_t_att, 
				s_y_pre_t_att, s_y_test_t_att, prac_t_att from subj_attendance
				where  group_id='".$group_id." '
				and academic_session='".$academic_session."' order by section, subject_id";
		$query=$this->db->query($sql);
		return $query->result_array();
	
	}
	
	////////////////////////////////////////////////////////
	function insert_update_no_of_class($data_for_insert_update)
	{
		$success=true;
		$sql="INSERT INTO subj_attendance (subject_id, group_id, academic_session,section,".$data_for_insert_update['col_name'].")
			VALUES (?, ?, ?, ?,?)
			ON DUPLICATE KEY UPDATE 
			".$data_for_insert_update['col_name']."=VALUES(".$data_for_insert_update['col_name'].")";
		$query = $this->db->query($sql,$data_for_insert_update);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		return $success;
	}
	
	/////////////////////////////////////////////////////////
	function Update_FirstTermMarks($AllData)
	{
		$success=true;
		///make the meril null for the session and student group
		foreach ($AllData as $data) 
		{
		$update_sql = " update subj_marks_detail set 
				       f_y_1st_att=".$data['att'].
                       ", f_y_1st_ct=".$data['ct'].
                       ", f_y_1st_ht_mcq=".$data['mcq'].
                       ", f_y_1st_ht_cq=".$data['cq'].
                       ", f_y_1st_ht_total=".$data['h_total'].
                       ", f_y_1st_gran_total=".$data['g_total'].
                       " where student_id='".$data['student_id']."' and academic_session='".$data['academic_session']."' and subject_id='".$data['subj']."'";
		
		$query=$this->db->query($update_sql);
		$report['error'] = $this->db->_error_number();
		$report['message'] = $this->db->_error_message();
		if($report == 0)
			$success= false;
		}
		
		return $success;
	}
	///////////////////////////////////////////////////////
	function UpdateProTestMarks($AllData)
	{
		$success=true;
		///make the meril null for the session and student group
		foreach ($AllData as $data)
		{
			$update_sql = " update subj_marks_detail set 
                                        f_y_pro_att=".$data['att'].
                                        ", f_y_pro_ht_mcq=".$data['mcq'].
                                        ", f_y_pro_ht_cq=".$data['cq'].
                                        ", f_y_pro_ht_prac=".$data['prac'].
                                        ", f_y_pro_ht_total=".$data['h_total'].
                                        " where student_id='".$data['student_id']."' and academic_session='".$data['academic_session']. "' and subject_id='".$data['subj']. "'";
		
			$query=$this->db->query($update_sql);
			$report['error'] = $this->db->_error_number();
			$report['message'] = $this->db->_error_message();
			if($report == 0)
				$success= false;
		}
	
		return $success;
	}
	/////////////////////////////////////////////////////
	function UpdatePreTestMarks($AllData)
	{
		$success=true;
		///make the meril null for the session and student group
		foreach ($AllData as $data)
		{
			$update_sql =  " update subj_marks_detail set 
                                        s_y_pre_att=".$data['att'].
                                        ", s_y_pre_ct=".$data['ct'].
                                        ", s_y_pre_ht_mcq=".$data['mcq'].
                                        ", s_y_pre_ht_cq=".$data['cq'].
                                        ", s_y_pre_ht_total=".$data['h_total'].
                                        ", s_y_pre_gran_total=".$data['g_total'].
                                        " where student_id='".$data['student_id']. "' and academic_session='".$data['academic_session']. "' and subject_id='".$data['subj']."'";
		
			$query=$this->db->query($update_sql);
			$report['error'] = $this->db->_error_number();
			$report['message'] = $this->db->_error_message();
			if($report == 0)
				$success= false;
		}
	
		return $success;
	}
	/////////////////////////////////////////////////////
	function UpdateTextExamMarks($AllData)
	{
		$success=true;
		///make the meril null for the session and student group
		foreach ($AllData as $data)
		{
			$update_sql =  " update subj_marks_detail set 
                                        s_y_test_att=".$data['att'].
                                       + ", s_y_prac_att=".$data['prac_att'].
                                       + ", s_y_t_p1_mcq=".$data['p1_mcq'].
                                       + ", s_y_t_p1_cq=".$data['p1_cq'].
                                       + ", s_y_t_p1_total=".$data['p1_total'].
                                       + ", s_y_t_p2_mcq=".$data['p2_mcq'].
                                       + ", s_y_t_p2_cq=".$data['p2_cq'].
                                       + ", s_y_t_p2_total=".$data['p2_total'].
                                       + ", s_y_test_gra_total=".$data['g_total'].
                                     //  + ", s_y_test_gpa=" + gpa
                                       + " where student_id='".$data['student_id']."' and academic_session='".$data['academic_session']."' and subject_id='".$data['subj']."'";
		
			$query=$this->db->query($update_sql);
			$report['error'] = $this->db->_error_number();
			$report['message'] = $this->db->_error_message();
			if($report == 0)
				$success= false;
		}
	
		return $success;
	}
	//////////////////////////////////////////////////////
}/// End Class